package com.g2room.eth.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BlockchainService {

//    @Autowired
//    Web3j web3j;

//    public BlockchainTransaction process(BlockchainTransaction trx) throws IOException {
//        EthAccounts accounts = web3j.ethAccounts().send();
//        EthGetTransactionCount transactionCount = web3j.ethGetTransactionCount(accounts.getAccounts().get(trx.getFromId()), DefaultBlockParameterName.LATEST).send();
//        Transaction transaction = Transaction.createEtherTransaction(accounts.getAccounts().get(trx.getFromId()), transactionCount.getTransactionCount(), BigInteger.valueOf(trx.getValue()), BigInteger.valueOf(21_000), accounts.getAccounts().get(trx.getToId()), BigInteger.valueOf(trx.getValue()));
//        EthSendTransaction response = web3j.ethSendTransaction(transaction).send();
//        if (response.getError() != null) {
//            trx.setAccepted(false);
//            return trx;
//        }
//        trx.setAccepted(true);
//        String txHash = response.getTransactionHash();
//        LOGGER.info("Tx hash: {}", txHash);
//        trx.setId(txHash);
//        EthGetTransactionReceipt receipt = web3j.ethGetTransactionReceipt(txHash).send();
//        if (receipt.getTransactionReceipt().isPresent()) {
//            LOGGER.info("Tx receipt: {}", receipt.getTransactionReceipt().get().getCumulativeGasUsed().intValue());
//        }
//        return trx;
//    }

}

